#include "../include/IRenderEntity.h"
#include "../include/CSpriteAnimation.h"
#include "../include/CSprite.h"

#include <SDL/SDL.h>

//**************************
//Description : Constructor
//Parameters : None
//Note : None
//**************************
IRenderEntity::IRenderEntity()
{
    m_Screen = NULL;

    m_vEntitySprites = NULL;
    m_vShotsAnimations = NULL;
    m_vPowerUpSprite = NULL;

    m_iState = STANDBY;
}

//**************************
//Description : Constructor
//Parameters : The screen
//Note : None
//**************************
IRenderEntity::IRenderEntity(SDL_Surface * _screen)
{
    m_Screen = _screen;

    m_vEntitySprites = NULL;
    m_vShotsAnimations = NULL;
    m_vPowerUpSprite = NULL;

    m_iState = STANDBY;
}

//**************************
//Description : Copy Constructor
//Parameters : A IRenderEntity
//Note : None
//**************************
IRenderEntity::IRenderEntity(IRenderEntity & _RenderEntity)
{
    m_Screen = _RenderEntity.m_Screen;

    if ( _RenderEntity.m_vEntitySprites != NULL )
    {
        m_vEntitySprites = new CSprite[NUMBER_STATES]();

        for ( int i = 0; i < NUMBER_STATES; i ++ )
        {
            m_vEntitySprites[i] = _RenderEntity.m_vEntitySprites[i];
        }
    }
    else
        m_vEntitySprites = NULL;

    m_vShotsAnimations = _RenderEntity.m_vShotsAnimations;

    if ( _RenderEntity.m_vPowerUpSprite != NULL )
    {
        m_vPowerUpSprite = new CSprite(*_RenderEntity.m_vPowerUpSprite);
    }
    else
        m_vPowerUpSprite = NULL;

    m_iState = _RenderEntity.m_iState;
}

//**************************
//Description : Destructor
//Parameters : None
//Note : None
//**************************
IRenderEntity::~IRenderEntity()
{
    if ( m_vEntitySprites != NULL )
        delete[] m_vEntitySprites;

    if ( m_vPowerUpSprite != NULL )
        delete m_vPowerUpSprite;
}

//**************************
//Description : Set the screen
//Parameters : The screen
//Return Value : None
//Note : None
//**************************
void IRenderEntity::SetScreen(SDL_Surface * _screen)
{
    if (m_Screen == NULL)
        m_Screen = _screen;
}

//**************************
//Description : Set sprites for the entity if it's not done
//Parameters : The tab of animations
//Return Value : None
//Note : None
//**************************
void IRenderEntity::SetSprites(CSpriteAnimation* _EntityAnimations)
{
    //if there isn't sprites set
    if (m_vEntitySprites == NULL)
    {
        //we create the tab of sprite
        m_vEntitySprites = new CSprite[NUMBER_STATES]();

        //for all states
        for (int i = 0; i < NUMBER_STATES; i++)
        {
            //we init the sprite and set the speed
            m_vEntitySprites[i].InitSprite(&_EntityAnimations[i], m_Screen);
        }
    }
}
